#include <nxos.h>
#include <string.h>

int __fmodeflags(const char *mode)
{
	int flags;
	if (strchr(mode, '+')) flags = NX_FILE_RDWR;
	else if (*mode == 'r') flags = NX_FILE_RDONLY;
	else flags = NX_FILE_WRONLY;
	if (strchr(mode, 'x')) flags |= NX_FILE_EXCL;
	//FIXME: if (strchr(mode, 'e')) flags |= NX_FILE_CLOEXEC;
	if (*mode != 'r') flags |= NX_FILE_CREAT;
	if (*mode == 'w') flags |= NX_FILE_TRUNC;
	if (*mode == 'a') flags |= NX_FILE_APPEND;
	return flags;
}
